import java.util.Arrays;

public class Student implements Cloneable{

    String name;
    Money m = new Money();

    public Student(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", m=" + m +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student temp =  (Student) super.clone();
        temp.m = (Money) this.m.clone();
        return temp;
    }

    public static void main(String[] args) throws CloneNotSupportedException{
        Student student1 = new Student("zhangsan");
        Student student2 = (Student) student1.clone();
        System.out.println(student1.name);
        System.out.println(student1.m.money);
        System.out.println(student2.name);
        System.out.println(student2.m.money);

        student2.name = "lisi";
        student2.m.money = 99.99;
        System.out.println(student1.name);
        System.out.println(student1.m.money);
        System.out.println(student2.name);
        System.out.println(student2.m.money);
    }
}

class Money implements Cloneable{
    public double money = 9.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
